
var isProfiling = false;
var profileResultsData;

function testHarnessInit() {

	// bind handlers for hide/show tools
	
	$('#test-addDP-heading').click(function() {
		$("#test-addDP-div").slideToggle("fast");
	});
	$('#test-profile-drawScene-heading').click(function() {
		$("#test-profile-drawScene-div").slideToggle("fast");
	});

	// bind handlers for tool commands
	
	$('#test-add-data-point').bind('click', function() {
		model.addDataPoint(
			$('#test-addDP-x').attr("value"),
			$('#test-addDP-y').attr("value"),
			$('#test-addDP-z').attr("value"));
	});
	
	$('#test-profile-drawScene-start').bind('click', function() {
		testStartProfiling();
	});
	$('#test-profile-drawScene-stop').bind('click', function() {
		testStopProfiling();
		displayProfilingData();
	});
}

function testStartProfiling() {
	profileResultsData = [];
	isProfiling = true;
}

function testStopProfiling() {
	isProfiling = false;
}

function testIsProfiling() {
	return isProfiling;
}

function addProfileData(areaStr,time) {
	if(profileResultsData[areaStr] == undefined) {
		profileResultsData[areaStr] = [];
	}
	profileResultsData[areaStr].push(time);
}

function displayProfilingData() {
	
	var output = "profiling data:<br/>";

	// for each profiling type
	for(i in profileResultsData) {
		// if no times recorded for this type, skip it
		if(profileResultsData[i] == undefined) {
			continue;
		}
		var numberOfTimesRecorded = profileResultsData[i].length;
		var cumulativeSumOfTimes = 0.0;
		// for each time recorded for this profiling type
		for(j in profileResultsData[i]) {
			// add time to cumulative sum
			cumulativeSumOfTimes += profileResultsData[i][j];
		}
		
		var time = "" + (cumulativeSumOfTimes/numberOfTimesRecorded);
		var time = time.substring(0,5);
		
		output += ""+i+": ";
		output += time;
		output += "ms (average of "+numberOfTimesRecorded;
		output += " iterations)<br/>";
	}
	
	$('#test-profile-drawScene-result').empty();
	
	$('#test-profile-drawScene-result').append(output);
}


